#ifndef _LOCK_H_
#define _LOCK_H_

#include "../define/define.h"

class lock
{
public:
   lock()
   {
		pthread_mutexattr_t mutexattr;
		pthread_mutexattr_init(&mutexattr);
		pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
		pthread_mutex_init(&m_lock, &mutexattr);
		pthread_mutexattr_destroy(&mutexattr);
	}

   ~lock()
   {
	   pthread_mutex_destroy(&m_lock);
   }

   bool EnterLock()
   {
	    return pthread_mutex_lock(&m_lock) == 0;
   }

   bool LeaveLock()
   {
	   return pthread_mutex_unlock(&m_lock) == 0;
   }

private:

   pthread_mutex_t m_lock;

};


class  func_lock
{
public:
  func_lock()
  {
	pthread_mutexattr_t mutexattr;
	pthread_mutexattr_init(&mutexattr);
	pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
	pthread_mutex_init(&m_lock, &mutexattr);
	pthread_mutexattr_destroy(&mutexattr);
	pthread_mutex_lock(&m_lock) == 0;
  }

  ~func_lock()
  {
	pthread_mutex_unlock(&m_lock) == 0;
	pthread_mutex_destroy(&m_lock);
  }
private:   
 pthread_mutex_t m_lock;
};

#endif
